package com.lw;

import java.awt.*;

/**
 * 用户控制的鱼
 */
public class MyFish {

    Image img = GameUtils.myFishImg_L;

    int x,y;//坐标
    int width=50,height=50;//大小

    int speed = 20;//移动速度
    int level = 1;//等级

    void logic(){
        //根据按键方向前进
        if(GameUtils.up){
            y = y-speed;
        }else if(GameUtils.down){
            y = y+speed;
        }

        if(GameUtils.left){
            x = x-speed;
            if(img!=GameUtils.myFishImg_L) img = GameUtils.myFishImg_L;
        }else if(GameUtils.right){
            x = x+speed;
            if(img!=GameUtils.myFishImg_R)  img = GameUtils.myFishImg_R;
        }


    }

    public void paintSelf(Graphics g){
        logic();
        g.drawImage(img,x,y,width+GameUtils.score,height+GameUtils.score,null);
    }

    /**
     * 绘制矩形用于碰撞检测
     * @return
     */
    public Rectangle getRec(){
        return new Rectangle(x,y,width+GameUtils.score,height+GameUtils.score);
    }
}
